package app.sevenc.lib_framework.api


/**
 * ScFrame$$UrlConfig.java
 * [app.sevenc.lib_compiler.utils.Consts.URL_CONFIG_CLASS_PACKAGE]
 */
const val URL_CONFIG_CLASS_NAME = "app.sevenc.lib_framework.compiler.api.ScFrame"+"$$"+"UrlConfig"

internal val baseUrl: String? get() = urlConfigOf("baseUrl")

internal val debugUrl: String? get() = urlConfigOf("debugUrl")

internal fun domains() = lazy {
  urlConfigOf<HashMap<String, String>>("domains")?: mutableMapOf()
}
internal fun downLoads() = lazy {
  urlConfigOf<HashMap<String, String>>("downLoads")?: mutableMapOf()
}

@Suppress("UNCHECKED_CAST")
private fun <T> urlConfigOf(fieldName: String): T? = try {
  val clazz = Class.forName(URL_CONFIG_CLASS_NAME)
  val urlConfig = clazz.newInstance()
  clazz.getField(fieldName)[urlConfig] as T?
} catch (e: NoSuchFieldException) {
  null
} catch (e: Exception) {
  e.printStackTrace()
  null
}